<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登陆</title>
<script src="{MODULE_URL}template/resources/js/jquery-2.1.1.min.js"></script>
<link href="{MODULE_URL}template/resources/js/bootstrap.min.css" rel="stylesheet">
<script src="{MODULE_URL}template/resources/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="{MODULE_URL}template/resources/layui/css/layui.css" media="all">
<script src="{MODULE_URL}template/resources/layui/layui.js"></script>
<link href="{MODULE_URL}template/mobile/default/base.css" rel="stylesheet">
<script src="{MODULE_URL}template/resources/js/swiper.min.js"></script>
<link href="{MODULE_URL}template/resources/js/swiper.min.css" rel="stylesheet">
<style>
html,body{height:100%; overflow:hidden;font-size:12px;}
body{ margin:0;background:url('{MODULE_URL}template/resources/bg.jpg');background-size:cover;}
#login{ margin:100px auto 80px auto; display:block; width:300px;}
h3{ font-size:18px; margin-bottom:30px;}
p{margin-bottom:10px; position:relative;}
.btngroup{}
</style>
</head>
<body onload="doinit()">
<div class="loginbox" style="display:none;">
	<form id="login" action="" method="post"  class="layui-form">
       <h3>账号登陆(管理员)</h3>
       <p><input id="username" type="text" name="username" value="{php echo $user}" required lay-verify="required" placeholder="请输入账号" autocomplete="off" class="layui-input"/></p>
       <p><input id="password" type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input"/></p>
       <p><input id="remember" type="checkbox" name="remember" title="记住账号" lay-skin="primary" checked /></p>
       <p><button class="layui-btn" lay-submit lay-filter="formDemo" style="width:100%;">登陆</button></p>
	   <p><span><a href="./index.php?i=1&c=entry&do=login&m=j_hmoney" style="text-decoration:underline">收银端登录</a></span></p>
	</form>
	<!--iframe src="../web/index.php?c=user&a=logout&" style="display:none"> </iframe-->
</div>

</body>
<script language="javascript">
function setCookie(cname,cvalue,exdays)
{
  var d = new Date();
  d.setTime(d.getTime()+(exdays*24*60*60*1000));
  var expires = "expires="+d.toGMTString();
  document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname)
{
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++) 
  {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
  return "";
}
function doinit(){
	var username=getCookie('remember-username-admin', "");
	var password=getCookie('remember-password-admin', "");
	$("[name=username]").val(username);
	$("[name=password]").val(password);
}
layui.use(['layer', 'element','form'], function(){
	var layer = layui.layer
	,element = layui.element
	,form = layui.form;
	
	layer.open({
		type: 1,
		title:0,
		anim:1,
		area:"400px",
		closeBtn:0,
		content:$(".loginbox").show(),
		success: function(layero, index){
			form.render('checkbox');
		}
	});
	form.on('submit(formDemo)', function(data){
		if(!data.field.username){
			layer.msg("请输入账号");
			return false;
		}
		if(!data.field.password){
			layer.msg("请输入密码");
			return false;
		}
		
	
		if($('#remember:checked').length == 1) {
			setCookie('remember-username-admin', $(':text[name="username"]').val());
			setCookie('remember-password-admin', document.getElementById('password').value);
		} else {
			setCookie('remember-username-admin', "");
			setCookie('remember-password-admin', "");
		}
	
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		
		$.ajax({ 
			type: "get",
			url: "../web/index.php?c=user&a=logout&", 
			async:false, 
			success: function(xmlobj){ 
			} 
		});
		
		$.post("../web/index.php?c=user&a=login&",data.field,function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(result.type=="success"){
				//location.href=result.redirect;
				location.href="../web/index.php?c=site&a=entry&do=indexs&m=j_hmoney";
				return false;
			}/*else if(result.redirect==""){
				//location.href="../web/index.php";
				location.href="../web/index.php?c=site&a=entry&do=indexs&m=j_hmoney";
				return false;
			}*/else{
				layer.msg(result.message,{icon:2,time:1000});
				return false;
			}
			
		});
		return false;
	});
});
</script>